package com.yuan.fmmall.controller;

import com.yuan.fmmall.service.CategoryService;
import com.yuan.fmmall.service.IndexImgService;
import com.yuan.fmmall.service.ProductService;
import com.yuan.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Yuan
 */
@RestController//@Controller 和 @ResponseBody 两个注解的结合体
@CrossOrigin
@RequestMapping("/index")
@Api(tags = "首页管理",value = "提供首页数据，显示所需的接口")
public class IndexController {
    @Autowired
    private IndexImgService indexImgService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductService productService;

    @GetMapping("/indexImg")
    @ApiOperation("首页轮播图")
    public ResultVO listIndexImgs(){
        return indexImgService.listIndexImgs();
    }

    @GetMapping("/category-list")
    @ApiOperation("商品分类查询接口（连接查询，需要在一开始知道有几层分类）")
    public ResultVO listCatetory(){
        return categoryService.listCategories();
    }

    @GetMapping("/category-list2")
    @ApiOperation("嵌套查询")
    @ApiImplicitParam(name = "parentId",dataType = "int",value = "父类等级id")
    public ResultVO listCategory2(int parentId){
        return categoryService.listCategories2(parentId);
    }

    @GetMapping("/list-recommends")
    @ApiOperation("查询推荐商品接口")
    public ResultVO listRecommendProducts() {
        return productService.listRecommendProducts();
    }
}
